package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Configuration表示该类为配置类
 * @Bean 标记到方法上，会将方法的返回值返回到ioc容器中
 * @author YDW
 * projectName:project2202_4
 * time:2022/6/11 14:37
 * description:
 */
@Configuration
public class RabbitMqConfig {

    //创建队列
    @Bean
    public Queue createQueue1(){
        return new Queue("my_queue",true,false,false);

    }
    @Bean
    public Queue createQueue2(){
        return new Queue("you_queue",true,false,false);

    }

    /*
    * 交换机的类型
    *   广播：FanoutExchange
    *   路由：DirectExchange
    *   主体：TopicExchange
    * */
    //创建交换机
    //主题模式
    @Bean
    public TopicExchange creatTopicExchange(){
        return new TopicExchange("my_topic_exchange",true,false);
    }
    //路由模式
    @Bean
    public DirectExchange creatDirectExchange(){
        return new DirectExchange("my_direct_exchange",true,false);
    }

    //广播模式
    @Bean
    public FanoutExchange creatFanoutExchange(){
        return new FanoutExchange("my_fanout_exchange",true,false);
    }

    //创建绑定对象
    //绑定广播模式
    @Bean
    public Binding  binding1(@Autowired FanoutExchange exchange,@Autowired Queue createQueue1){
        return BindingBuilder.bind(createQueue1).to(exchange);
    }
    @Bean
    public Binding  binding2(@Autowired FanoutExchange exchange,@Autowired Queue createQueue2){
        return BindingBuilder.bind(createQueue2).to(exchange);
    }

    //绑定路由模式
    @Bean
    public Binding  binding3( DirectExchange exchange,Queue createQueue1){
        return BindingBuilder.bind(createQueue1).to(exchange).with("update");
    }

    @Bean
    public Binding  binding4( DirectExchange exchange,Queue createQueue2){
        return BindingBuilder.bind(createQueue2).to(exchange).with("log");
    }

}
